/**
 * @(#)BasicPerson.java
 *
 *
 * @author 
 * @version 1.00 2009/9/3
 */

package emap;

public class BasicPerson implements Controllable {
	private int imgGfxNo;
	private int facingDir;
	private int curSpeed;
	private int doAnim;
	private Rect myColArea;
	private Coord drawOffset;
	private Coord myPos;
	private int myY;
	private Controller myCon;
    public BasicPerson() {
    	imgGfxNo=0;
    	facingDir=0;
    	curSpeed=2;
    	doAnim=-1; //-1 stop 0,1,2,3 loop
    	myColArea=new Rect(-16,-24,16,24);
    	drawOffset=new Coord(-16,-32);
    	myPos=new Coord(0,0);
    	myY=0; //In pixels, not tiles! Important!
    }
    public Controller getController(){return myCon;}
    public void setController(Controller a){myCon=a;}
    public int getImgGfxNo(){return imgGfxNo;}
    public void setImgGfxNo(int a){imgGfxNo=a;}
    public int getFacingDir(){return facingDir;}
    public void setFacingDir(int a){facingDir=a;}
    public int getCurSpeed(){return curSpeed;}
    public void setCurSpeed(int a){curSpeed=a;}
    public int getAnim(){return doAnim;}
    public void setAnim(int a){doAnim=a;}
    public Rect getColArea(){return new Rect(myColArea);}
    public void setColArea(Rect a){myColArea=new Rect(a);}
    public Coord getDrawOffset(){return new Coord(drawOffset);}
    public void setDrawOffset(Coord a){drawOffset=new Coord(a);}
    public Coord getPos(){return new Coord(myPos);}
    public void setPos(Coord a){myPos=new Coord(a);}
    public int getY(){return myY;}
    public void setY(int a){myY=a;}
    public void moveUp(){myPos.mvy(-curSpeed);facingDir=3;if(doAnim==(-1)) doAnim=0;}
    public void moveDown(){myPos.mvy(curSpeed);facingDir=0;if(doAnim==(-1)) doAnim=0;}
    public void moveLeft(){myPos.mvx(-curSpeed);facingDir=1;if(doAnim==(-1)) doAnim=0;}
    public void moveRight(){myPos.mvx(curSpeed);facingDir=2;if(doAnim==(-1)) doAnim=0;}
    public void actionA(){System.out.println("A");}
    public void actionB(){System.out.println("B");}
    public void idle(){doAnim=-1;}
    public ObjectDrawn getOD(){return new ObjectDrawn(myPos.X,myPos.Y-myY,myY/32,imgGfxNo,facingDir,(doAnim<0)?0:doAnim);}
    public void myAction(){if(doAnim>=0) doAnim++;if(doAnim>3) doAnim=0;}
    public void moveBy(int xs,int ys,Coord mapDim){ //yum! the x and y diffs, then the bounds
		myPos.X+=xs;
		myPos.Y+=ys;
		if(myPos.X<0) myPos.X=0;
		if(myPos.Y<0) myPos.Y=0;
		if(myPos.X+32>mapDim.X) myPos.X=mapDim.X-32;
		if(myPos.Y+48>mapDim.Y) myPos.Y=mapDim.Y-48;
	}
}